<template>
  <BaseModal title="更新团费缴至时间"
    :visible="visible"
    @cancel="handleCancel"
    :confirm-loading="confirmLoading"
    @ok="handleOk" width="800px" destroyOnClose>
    <custom-form
      ref="ruleForm"
      :isValidate="true"
      :editModel="''"
      :rules="rules"
      :form="formInfo"
      :formList="formItemList"
    ></custom-form>
  </BaseModal>
</template>

<script>
import BaseModal from '@/components/BaseModal'
import { packageConfirm } from '@/utils/baseAction.js'
import { updateDuesEndTime } from '@/api/partyMasses/leagueManage'

export default {
  name:'a'+ Date.now(),
  components: {
    BaseModal,
  },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    initData: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      confirmLoading: false,
      formInfo: {},
      rules: {
        duesEndTime: [{ required: true, message: '请选择团费缴至时间时间', trigger: 'change' }],
      },
    }
  },
  computed: {
    formItemList() {
      return [
        {
          label: '团费缴至时间时间',
          keyName: 'duesEndTime',
          type: 'a-date-picker',
          span: 12,
        }
      ]
    },
  },
  watch: {
    initData: {
      immediate: true,
      deep: true,
      handler(val) {
        this.formInfo = { ...val } || {}
      },
    },
  },
  methods: {
    confirmSub(text,func) {
      let _this = this;
      this.$confirm({
        title: '温馨提示',
        content: text,
        onOk:() => {
          return func()
        },
        onCancel() {
        },
      });
    },
    submitFunc() {
      const params = {
        ...this.formInfo,
      }
      params.duesEndTime = this.$dateFormat(params.duesEndTime, 'D')
      this.confirmLoading = true;
      return updateDuesEndTime(params).then((res) => {
        this.confirmLoading = false;
        if (res && res.code == 0) {
          this.$message.success('更新成功');
          this.handleCancel();
          this.$emit('ok')
        } else {
          this.$message.error('更新失败！');
        }
      })
    },
    handleOk() {
      this.$refs.ruleForm.validate((valid) => {
        if (!valid) {
          this.$message.warning("请填写完所有必填项信息")
          return
        }
        this.confirmSub('确认提交吗？', this.submitFunc);
      })
    },
    handleCancel() {
      this.$emit('update:visible')
    },
  },
}
</script>

<style>
</style>
